/*
 *  Copyright 2010 johan.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package nu.zoom.catonine.swing.tail;

import nu.zoom.catonine.swing.tail.TimestampDocument;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import nu.zoom.swing.action.AbstractTypedAction;
import nu.zoom.ui.Resources;
import nu.zoom.ui.Resources.ResourceNotFoundException;

/**
 * Action to insert a mark after the latest displayed log entry.
 * 
 * @author "Johan Maasing" &lt;johan@zoom.nu&gt;
 */
public class StampAction extends AbstractTypedAction {
	private static final long serialVersionUID = 1L;
	private final TimestampDocument document;

	public StampAction(final Resources resources, final TimestampDocument document) throws ResourceNotFoundException {
		this.document = document;
		setIcon(resources.getIcon("nu.zoom.catonine.tail.stamp.icon"));
		setName(resources.getMessage("nu.zoom.catonine.tail.stamp"));
		setToolTip(resources.getMessage("nu.zoom.catonine.tail.stamp.tt"));
		setMnemonicKey(KeyEvent.VK_T);
		setAcceleratorKey(KeyEvent.VK_T, InputEvent.CTRL_DOWN_MASK);
		if (document == null) {
			setEnabled(false);
		}
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		document.addStampAfterLast();
	}
}
